package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.Empresa;



public class FornecedorDAO {
	
	
	public boolean insert(Empresa f){
		
		String sql = "insert into fornecedor values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
		
		
		try{
			
			  	
			   PreparedStatement prep = ConnectionFactory.getInstance().prepareStatement(sql);
			   prep.setString (1, f.getStrRazaoSocial());
			   prep.setString (2, f.getCNPJ());
			   prep.setString (3, f.getLogradouro());
			   prep.setString (4, f.getComplemento());
			   prep.setInt(5, f.getNum());
			   prep.setString (6, f.getBairro());
			   prep.setString (7, f.getCEP());
			   prep.setString (8, f.getCidade());
			   prep.setString (9, f.getEstado());
			   
			   prep.execute();
			   
			   ConnectionFactory.getInstance().close();
			   
			   return true;
			   
	
		}catch(SQLException e){
			
			e.printStackTrace();
			return false;
			
		}catch(Exception ex){
			
			ex.printStackTrace();
			return false;
			
		}
		

	
	}
	/*
	public boolean update(Empresa f){
		
		
		String sql = "update fornecedor set razao_social = ?, cnpj = ?, logradouro = ?, complemento = ?, numero = ?, bairro = ?, cep = ?, cidade = ?, estado = ?";
		
		
		try{
			
			  	
			   PreparedStatement prep = ConnectionFactory.getInstance().prepareStatement(sql);
			   prep.setString (1, f.getStrRazaoSocial());
			   prep.setString (2, f.getCNPJ());
			   prep.setString (3, f.getLogradouro());
			   prep.setString (4, f.getComplemento());
			   prep.setInt(5, f.getNum());
			   prep.setString (6, f.getBairro());
			   prep.setString (7, f.getCEP());
			   prep.setString (8, f.getCidade());
			   prep.setString (9, f.getEstado());
			   
			   prep.execute();
			   
			   ConnectionFactory.getInstance().close();
			   
			   return true;
			   
	
		}catch(SQLException e){
			
			e.getMessage();
			return false;
			
		}catch(Exception ex){
			
			ex.getMessage();
			return false;
			
		}	
	
		
	}
	*/
	/*
	public boolean delete(Empresa f){
		
		
		String sql = "delete from fornecedor where cnpj = ?";
		
		
		try{
			
			  	
			   PreparedStatement prep = ConnectionFactory.getInstance().prepareStatement(sql);
			   prep.setString (1, f.getCNPJ());
			 
			   prep.execute();
			   
			   ConnectionFactory.getInstance().close();
			   
			   return true;
			   
	
		}catch(SQLException e){
			
			e.getMessage();
			return false;
			
		}catch(Exception ex){
			
			ex.getMessage();
			return false;
			
		}	

	}
*/
	public static ResultSet selectALL(Empresa f){
		
		
		String sql = "select * from fornecedor where cnpj = ?";	
		
		try{
			
		  	
			   PreparedStatement prep = ConnectionFactory.getInstance().prepareStatement(sql);
			   prep.setString (1, f.getCNPJ());
			 
			   ResultSet rs = prep.executeQuery();
			   
			   ConnectionFactory.getInstance().close();
			   
			   return rs;
			   
	
		}catch(SQLException e){
			
			e.getMessage();
			return null;
			
		}catch(Exception ex){
			
			ex.getMessage();
			return null;
			
		}	

	}
	
	
	
	public static ResultSet selectALL(){
		
		
		String sql = "select * from fornecedor";	
		
		try{
			
		  	
			   PreparedStatement prep = ConnectionFactory.getInstance().prepareStatement(sql);
			 
			   ResultSet rs = prep.executeQuery();
			   
			   ConnectionFactory.getInstance().close();
			   
			   return rs;
			   
	
		}catch(SQLException e){
			
			e.getMessage();
			return null;
			
		}catch(Exception ex){
			
			ex.getMessage();
			return null;
			
		}	

	}

}
